package com.xkdx.caipiao.presistence.hongbao;

import java.util.ArrayList;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xkdx.caipiao.module.network.AbsModule;

public class HongbaoModule extends AbsModule {
	public int flag = 0;
	public ArrayList<HongbaoInfo>list1;
	public ArrayList<HongbaoInfo>list2;
	@Override
	public void parseData() throws Exception {
		try {
			backJson = (JSONArray) result;
			if(flag == 0){
			list1 = new ArrayList<HongbaoInfo>();
			for (int i = 0; i < backJson.size(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("GetRedPacketUseList")) {
					parseHongbao(jsonObj.getJSONArray("DetailInfo"));
				}

			}
			}else if(flag == 1){
				list2 = new ArrayList<HongbaoInfo>();
				for (int i = 0; i < backJson.size(); i++) {
					jsonObj = (JSONObject) backJson.get(i);
					String sortOfAct = jsonObj.getString("Act");
					if (sortOfAct.equals("GetRedPacketDisUseList")) {
						parseHongbao(jsonObj.getJSONArray("DetailInfo"));
					}

				}
			}
		} catch (Exception e) {
			throw e;
		}

	}
	private void parseHongbao(JSONArray jsonArray) throws Exception {
		try {
		JSONArray array = jsonArray;
		for (int i = 0; i < array.size(); i++) {

			JSONObject obj = array.getJSONObject(i);
			HongbaoInfo hongbaoInfo = new HongbaoInfo();
			hongbaoInfo.setId(obj.getString("id"));
			hongbaoInfo.setPacketid(obj.getString("packetid"));
			hongbaoInfo.setCtime(obj.getString("ctime"));
			hongbaoInfo.setActtype(obj.getString("acttype"));
			hongbaoInfo.setUid(obj.getString("uid"));
			hongbaoInfo.setOid(obj.getString("oid"));
			hongbaoInfo.setStatus(obj.getString("status"));
			hongbaoInfo.setOrderid(obj.getString("orderid"));
			hongbaoInfo.setDetail(obj.getString("detail"));
			hongbaoInfo.setFacevalue(obj.getString("facevalue"));
			hongbaoInfo.setValidity(obj.getString("validity"));
			if(0 == flag){
				list1.add(hongbaoInfo);
			}else if(1 == flag){
				list2.add(hongbaoInfo);
			}
		}

	} catch (Exception e) {

		throw e;
	}
}
	

}
